part of 'widgets.dart';

class VanDocTheme extends _VanDocTheme {
  static final light = VanDocThemeData.fromJson(Brightness.light, kVanDocThemeDataLight);
  static final dark = VanDocThemeData.fromJson(Brightness.dark, kVanDocThemeDataDark);

  static bool support(VanCssKey key) => _VanDocTheme.support(key);

  static dynamic get<T>(BuildContext context, {required VanCssKey key, T? defaultValue}) => _VanDocTheme.get(context, key: key);

  static VanDocThemeData of(BuildContext context) {
    final docTheme = VanProvider.of<VanDocTheme>(context);
    var data = docTheme?.provide;
    if (data != null) return data;
    final brightness = docTheme?.brightness ?? Theme.of(context).brightness;
    if (docTheme != null) {
      if (brightness == Brightness.dark) {
        data = docTheme.themeDark;
      } else if (brightness == Brightness.light) {
        data = docTheme.themeLight;
      }
      data ??= docTheme.theme;
    }
    data ??= brightness == Brightness.dark ? VanDocTheme.dark : VanDocTheme.light;

    return data;
  }

  final Brightness? brightness;
  final VanDocThemeData? theme;
  final VanDocThemeData? themeDark;
  final VanDocThemeData? themeLight;

  const VanDocTheme({
    super.key,
    required super.child,
    this.theme,
    this.brightness,
    this.themeDark,
    this.themeLight,
  }) : super(provide: theme);
}
